package com.supersit.greensproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.supersit.greensproject.R;

import java.util.List;

/**
 * Created by cong on 2016/7/13.
 */
public class SettingDataAdapter extends BaseAdapter {
    private Context context;
    private List<String> data;
    private LayoutInflater inflater;

    public SettingDataAdapter(Context context, List<String> data) {
        this.context = context;
        this.data = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (data.size() < 1 || null == data) {
            return 0;
        } else {
            return data.size();
        }

    }

    @Override
    public Object getItem(int position) {
        if (data.size() < 1 || null == data) {
            return null;
        } else {
            return data.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HolderView holderView;
        if (null == convertView) {
            holderView = new HolderView();
            convertView = inflater.inflate(R.layout.item_subject_data, null);
            holderView
                    .tvName = (TextView) convertView.findViewById(R.id.tv_item_name);
            convertView.setTag(holderView);
        } else {
            holderView = (HolderView) convertView
                    .getTag();
        }
        holderView.tvName.setText(data.get(position).toString());
        return convertView;
    }

    class HolderView {
        TextView tvName;
    }
}
